package com.bieyang.anjia.ui.activity;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler.Callback;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import cn.sharesdk.onekeyshare.OnekeyShare;

import com.bieyang.anjia.R;
import com.bieyang.anjia.module.HelpInfo;
import com.bieyang.anjia.module.NewsInfo;
import com.bieyang.anjia.net.NetManager;
import com.bieyang.anjia.ui.adapter.HelpAdapter;
import com.bieyang.anjia.ui.adapter.NewsAdapter;
import com.bieyang.anjia.utils.Constants;
import com.bieyang.anjia.utils.Show;

public class AcHelp extends BaseFlingActivity implements OnClickListener, Callback {
	ListView lvHelp;
	Context con;
	List<HelpInfo> helpList;
	 HelpAdapter adapter  ;
	 
	
	
	private Handler handler = new Handler() {
		public void handleMessage(android.os.Message msg) {

			switch (msg.what) {
			case Constants.GET_HELP_SUCESS:
				helpList = NetManager.helpList;
//				helpList=msg.getData().getParcelable("helpInfo");

				if (null == helpList || helpList.size() == 0) {
					Show.toast(con, R.string.tip_no_data);
				} else {
					refreshData();
				}

//				Log.d("newsList", newsList.toString());
//				Show.toast(AcFindNews.this, R.string.tip_get_news_ok);

				break;
			case Constants.GET_NEWS_FAIL:
				Show.toast(con, R.string.tip_get_news_fail);
				break;

			default:
				break;
			}
		};

	};
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ac_help);
		con=AcHelp.this;
		//		ShareSDK.initSDK(this);
		//		findViewById(R.id.btnShare).setOnClickListener(this);
		findViewById(R.id.btnBack).setOnClickListener(this);
		
	  lvHelp=	(ListView) findViewById(R.id.lvHelp);
	  lvHelp.setOnItemClickListener(new OnItemClick());
	  App.netManager.getHelp(con,handler);
	  
		 
	}
 
	
	void refreshData() {
		helpList = NetManager.helpList;
		if (null == helpList || (helpList.size() == 0)) {
			adapter = new HelpAdapter(con);
			lvHelp.setAdapter(adapter);
		} else {
			adapter = new HelpAdapter(con, helpList);
			lvHelp.setAdapter(adapter);
		}

	}
	
	

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btnBack:
			finish();
			break;
		case R.id.btnShare:
			OnekeyShare oks = new OnekeyShare();
			// 分享时Notification的图标和文字
			oks.setNotification(R.drawable.icon, AcHelp.this.getString(R.string.app_name));
			// text是分享文本，所有平台都需要这个字段
			oks.setText("分享安加");

			oks.show(v.getContext());
			break;
		}
	}

	//	@Override
	//	protected void onDestroy() {
	//		ShareSDK.stopSDK(this);
	//		super.onDestroy();
	//
	//	}

	@Override
	public boolean handleMessage(Message msg) {
		return false;
	}
	
	
	class OnItemClick implements OnItemClickListener {

		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {

			Intent intent = new Intent(con, AcHelpDetail.class);
			intent.putExtra("webUrl", helpList.get(position).webUrl);
			startActivity(intent);
		}

	}

}
